﻿
namespace Patterns4Net.Tests.PatternEnforcer.Core.Patterns.Regression
{
    using System;
    using System.Diagnostics.Contracts;
    using NUnit.Framework;
    using Patterns4Net.Core.CecilExtensions;
    using Patterns4Net.PatternEnforcer.Core.Patterns;

    public class DeepImmutableCheckerTest : PatternCheckerTestBase
    {
        [Test]
        [TestCase(typeof(DeeplyImmutable))]
        [TestCase(typeof(MutateParent))]
        [TestCase(typeof(UncorrectDeeplyImmutable))]
        public void RunAllTests(Type type)
        {
            Contract.Requires(type != null);
            this.TestChecker(new ImmutableChecker(), type, new Patterns4Net.Core.Patterns.Immutable(type.GetTypeDefinition(), true));
        }

        [PatternTest(true)]
        public class DeeplyImmutable
        {
            public DeeplyImmutable Parent { get; private set; }

            public NestedImmutable Nested { get; private set; }
        }

        public class NestedImmutable
        {
            public int X { get; private set; }
        }

        [PatternTest(false)]
        public class MutateParent
        {
            public MutateParent Parent { get; private set; }

            protected void MakeOrphan()
            {
                this.Parent = null;
            }
        }

        [PatternTest(false)]
        public class UncorrectDeeplyImmutable
        {
            public int ThisIsOk { get; private set; }

            public int ThisIsOkToo { get; private set; }

            public MutableGuy Parent { get; private set; }
        }

        public class MutableGuy
        {
            public string Name { get; set; }
        }
    }
}
